<template>
  <div class="center">
    <!-- <a-switch
      default-checked
      checked-children="dark"
      un-checked-children="light"
      @change="changeTheme"
      style="
       position: absolute;
    right: 265px;
    top: 14px;"
    />-->

    <!-- <a-button
      type="primary"
      style="
    position: absolute;
    left: 265px;
    top: 14px;"
      @click="toggleCollapsed"
    >
      <a-icon :type="collapsed ? 'menu-unfold' : 'menu-fold'" />
    </a-button>-->

    <a-menu
      mode="inline"
      :theme="theme"
      @click="handleClick"
      :inline-collapsed="collapsed"
      :selected-keys="currentKeys"
      style="padding: 16px 0px;width:265px;"
      :default-selected-keys="defaultSelectedkeys"
      :default-open-keys="defaultOpenKeys"
    >
      <a-sub-menu v-for="(item, index) in MenuInfo" :key="'Menu'+index">
        <!-- :disabled="SelectList.indexOf(item.MenuId)==-1 ?true:false" -->

        <span slot="title">
          <a-icon type="appstore" />
          <span>{{ item.MenuName }}</span>
        </span>
        <a-menu-item
          v-for="(v, i) in item.sysMenu"
          :key="'Menu'+index+'subMenu'+i"
          :disabled="SelectList.indexOf(v.MenuId)==-1 ?true:false"
        >
          <div @click="routePush(v,index,i)">{{ v.MenuName }}</div>
        </a-menu-item>
      </a-sub-menu>
    </a-menu>
  </div>
</template>
<script>
export default {
  data() {
    return {
      currentKeys: [],
      theme: 'dark',
      collapsed: false,
      RoleId: '',
      RoleInfo: '',
      SelectList: [],
      MenuInfo: [],
      defaultSelectedkeys: [],
      defaultOpenKeys: [],
    }
  },
  created() {
    const that = this
    this.getRoleAuthInfo()
    this.defaultSelectedkeys[0] = 'Menu' + 0 + 'subMenu' + 0
    that.getMenuInfo()
  },
  mounted() {
    const that = this
  },
  methods: {
    routePush(v, index, i) {
      console.log('v :>> ', v.MenuId)
      let current = 'Menu' + index + 'subMenu' + i
      this.currentKeys = [current]
      this.$forceUpdate()
      const MenuId = v.MenuId
      let path = ''
      //  根据MenuId 跳转
      switch (MenuId) {
        case 'SMEManage':
          path = 'sme/manage'
          break
        case 'SysButtonManage':
          path = 'system/buttonManage'
          break
        case 'SysMenuManage':
          path = 'system/menuManage'
          break
        case 'SysDeptManage':
          path = 'user/divisionalManage'
          break
        case 'SysRoleManage':
          path = 'user/roleManage'
          break
        case 'SysUserList':
          path = 'user/list'
          break
        case 'IndexPageManage':
          path = 'system/indexManage'
          break
        case 'BaseLineAddLearnManage':
          path = 'BaseLineAndLessonLearn'
          break
        case 'gongyingshangScheme':
          path = 'scheme/supplierSolution'
          break
        case 'InnovationSchemeManage':
          path = 'Innovation'
          break
        case 'schemeList':
          path = 'scheme/List'
          break
        case 'LogManagement':
          path = 'LogManagement'
          break
        default:
          path = 'scheme/List'
          break
      }
      console.log('this.$router :>> ', this.$router.history.current.path)
      if (
        '/' + path !== this.$router.history.current.path &&
        this.SelectList.indexOf(v.MenuId) !== -1
      ) {
        this.$router.push({ path: '/' + path })
      }
    },
    handleClick(e) {},
    changeTheme(checked) {
      this.theme = checked ? 'dark' : 'light'
    },
    toggleCollapsed() {
      this.collapsed = !this.collapsed
    },
    getRoleAuthInfo(item) {
      const that = this
      this.RoleId = JSON.parse(sessionStorage.getItem('BackUserInfo'))[0].RoleId
      console.log('this.RoleId :>> ', this.RoleId)
      const a = {
        method: 'SysRoleAuthority_Que',
        userId: window.userId || 1,
        sign: '1',
        currentPage: 0,
        limit: 0,
        datas: {
          RoleId: this.RoleId,
        },
      }
      this.$post(a).then((result) => {
        that.SelectList = result.SelectList
        console.log('SelectList :>> ', this.SelectList)
      })
    },
    getMenuInfo() {
      const that = this
      const a = {
        method: 'SysMenu_Que',
        userId: window.userId || 1,
        sign: '1',
        currentPage: 0,
        limit: 0,
        datas: {},
      }
      this.$post(a).then((result) => {
        console.log('MenuInfo :>> ', result)
        that.MenuInfo = result.data
        that.$nextTick(() => {
          if (that.MenuInfo.length > 0) {
            that.MenuInfo.map((itme, index) => {
              let str = 'Menu' + index
              console.log('str :>> ', str)
              that.defaultOpenKeys.push(str)
            })
          }
          console.log('this.defaultOpenKeys :>> ', this.defaultOpenKeys)
        })
      })
    },
  },
}
</script>
<style lang="less" scoped>
.main {
}
.center {
  height: 100%;
  background-color: #001529;
}
</style>
